const TOKEN_KEY = 'geek-app'

// 获取token
// 此处 将获取到的token 字符串，先转换成JSON格式的对象，再返回
// const getToken = () => localStorage.getItem(TOKEN_KEY)
const getToken = () => JSON.parse(localStorage.getItem(TOKEN_KEY)) || {}

// 设置token
const setToken = data => localStorage.setItem(TOKEN_KEY, JSON.stringify(data))

// 移除token
const removeToken = () => localStorage.removeItem(TOKEN_KEY)

// 判断是否登录（授权）
const isAuth = () => !!getToken()

export { getToken, setToken, removeToken, isAuth }
